﻿$(function () {
    twiSelf.init();
});

Twi.TDCP.TaskPublish = {
    Vars: {
        autoHeight: 0,
        projectMappingName: 'BIM08',
        taskMappingName: 'TDCP03',
        sltProjectID: ''        
    }//end Vars

    ,init:function(){
        twiVars.autoHeight = twiModule.GetAutoHeight();
        twiSelf.Grid.createProjectGrid();
        twiSelf.Grid.createTaskGrid();
    }//end init    

    , Grid: {
        createProjectGrid: function () {
            $('#projectGrid').datagrid({
                url: Twi.Url,
                width: '100%',
                title: "项目列表",
                height:  twiVars.autoHeight,
                fitColumns: true,
                singleSelect: true,
                rownumbers: true,                
                columns: [twiSelf.Fn.Project.getColumns()],
                queryParams:twiSelf.Fn.Project.getQueryParam(),                
                onClickRow: function (rowIndex, rowData) {
                    twiVars.sltProjectID = rowData.FID;
                    $('#taskGrid').datagrid('load', twiSelf.Fn.Task.getQueryParam());
                }
            });
        }//end createProjectGrid

        , createTaskGrid: function () {
            $('#taskGrid').datagrid({
                url: Twi.Url,
                width: '100%',
                title: "任务列表",
                height: twiVars.autoHeight,
                fitColumns: true,
                singleSelect: true,
                pagination: true,
                rownumbers: true,
                pageSize: Twi.pageSize,
                pageList: twiModule.EasyUI.pageList,
                columns: [twiSelf.Fn.Task.getColumns()],
                queryParams: twiSelf.Fn.Task.getQueryParam()
            });
        }//end createTaskGrid

    } //end Grid

    , Fn: {
        Project: {
            getColumns: function () {
                return [
                        { field: 'FABBREVIATION', title: '项目编号', width: 150, align: 'center' },
                        { field: 'FSHORTTEXT', title: '项目名称', width: 150, align: 'center' }
                ];
            }//end getColumns
            ,getQueryParam: function () {
                return {
                    cn: 'PageCommon',
                    mn: 'TDCP',
                    mn2: 'GetBySimpleCondition',
                    data: JSON.stringify({
                        TableName: twiVars.projectMappingName,
                        OrderFields: 'FSort',
                        Condition: {
                            FIsDeleted: 0
                        }
                    }),
                    dataSign: 'EasyUI'
                };
            }//end getQueryParam
        }//end Project

        ,Task: {
            getColumns: function () {
                return [
                        { field: 'FNAME', title: '任务名称', width: 150, align: 'center' },
                        { field: 'FTASKTYPENAME', title: '任务类别', width: 150, align: 'center' },
                        { field: 'FIMPORTANTLEVEL', title: '重要程度', width: 60, align: 'center' },
                        { field: 'FURGENCYLEVEL', title: '紧急程度', width: 60, align: 'center' },
                        { field: 'FWORKLOADINDEX', title: '工作量指数', width: 60, align: 'center' },
                        { field: 'FEXPECTCOMPLETETIME', title: '期望完成时间', width: 120, align: 'center' },
                        { field: 'FCURRENTEXECUTOR', title: '当前执行人', width: 150, align: 'center' },
                        { field: 'FPUBLISHER', title: '发布人', width: 60, align: 'center' },
                        { field: 'FPUBLISHTIME', title: '发布时间', width: 120, align: 'center' },
                        {
                            field: 'FTAG', title: '任务状态', width: 60, align: 'center', formatter: function (value, row, index) {
                                if (value == "0") {
                                    return "待执行";
                                }
                                else if (value == "1") {
                                    return "执行中";
                                }
                                else if (value == "2") {
                                    return "已完成"
                                }
                                else {
                                    return value;
                                }
                            }
                        }
                ];
            }//end getColumns
            ,getQueryParam: function () {
                return {
                    cn: 'PageCommon',
                    mn: 'TDCP',
                    mn2: 'GetPagingDataByCondition',
                    needPaging: true,
                    data: JSON.stringify({
                        TableName: twiVars.taskMappingName,
                        OrderFields: 'FInsertDateTime',
                        Condition: {
                            FProjectID: twiVars.sltProjectID
                        }
                    }),
                    dataSign: 'EasyUI'
                };
            } //end getQueryParam

        }//end Task

    }//end Fn

} //end Twi.TDCP.TaskPublish

var twiSelf = Twi.TDCP.TaskPublish;
var twiVars = twiSelf.Vars;